/*************************************************************************
> File Name: 006.c
> Author: icebear
> Mail: 3322366195@qq.com
> Created Time: 2023-07-24 16:40:02
> Description: 二维数组行列互换
************************************************************************/

#include <stdio.h>
void swap(int *num1, int *num2);
int main(int argc, char const *argv[])
{

    int arr[3][3];
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            arr[i][j] = i * 3 + j;
        }
    }
    printf("the orginal arr is:\n");
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            printf("%d ", arr[i][j]);
        }
        printf("\n");
    }
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < i; j++)
        {
            swap(&arr[i][j], &arr[j][i]);
        }
    }
    printf("the new arr is:\n");
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            printf("%d ", arr[i][j]);
        }
        printf("\n");
    }

    return 0;
}

void swap(int *num1, int *num2)
{
    if (num1 != num2)
    {
        *num1 = *num1 ^ *num2;
        *num2 = *num1 ^ *num2;
        *num1 = *num1 ^ *num2;
    }
}
